import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs

# 制造聚类的散点
x, y = make_blobs(n_samples=1000,
                  n_features=2,
                  centers=[[-1,-1],[0,0],[1,1],[2,2]],
                  cluster_std=[0.4,0.2,0.2,0.2],
                  random_state=22)
sse_list = []
for k in range(1,20):
    model = KMeans(n_clusters=k)
    model.fit(x)
    sse_list.append(model.inertia_) # sse

plt.figure(figsize=(15,8),dpi=80)
plt.plot(range(1,20),sse_list,marker="o")
plt.show()










